package org.fjsei.yewu.jyjc;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import com.alibaba.fastjson2.annotation.JSONField;
//import com.fjtj.seip.framework.common.exception.ServiceException;
import com.rs.sm.Encoder;
import lombok.Data;

/**
 * 监察统一返回对象
 *
 * @author 黄金周
 * @since 2024/5/13 下午7:54
 */
@Data
public class FjAmrRespWrapper<D> {

    @JSONField(name = "STATUS")
    private Integer status;

    @JSONField(name = "MSG")
    private String msg;

    @JSONField(name = "DATA")
    private D data;

    @JSONField(name = "TOTAL")
    private Long total;

    public <T> T parseData(String sm4Key, Class<T> clazz) {
        if (!(this.data instanceof String)) {
//            throw new ServiceException("非加密数据");
        }

        return JSON.parseObject(Encoder.ecb((String) this.data, sm4Key), clazz);
    }

    public <T> T parseData(String sm4Key, TypeReference<T> typeReference) {
        if (!(this.data instanceof String)) {
//            throw new ServiceException("非加密数据");
        }

        return JSON.parseObject(Encoder.ecb((String) this.data, sm4Key), typeReference);
    }
}
